package org.huangjie.ddns;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;

/**
 * 更新ipv6地址
 * 服务地址：https://ydns.io/hosts/
 * 账号：1773506379@qq.com
 * 密码：Hj19981011
 *
 * @author Huang Jie
 * @date 2024/05/18
 */
public class YDnsDDns implements DDns<String> {
    private String username = "18E3DEPUPvwFFkJZouoF";
    private String password = "S63UDD74DNXVXS6IFVVAUX2AN8DRF4";
    private String host = "application.ydns.eu";
    private String ydnsUrl = "https://ydns.io/api/v1/update/";

    @Override
    public String update(String ip) {
        String url = StrUtil.format("{}?host={}&ip={}",ydnsUrl, host, ip);
        String body = HttpRequest.get(url)
                .basicAuth(username, password)
                .execute().body();
        if (body.contains("good")) {
            System.out.println("更新成功:"+body);
        } else if (body.contains("nochg")) {
            System.out.println("IP地址未改变:"+body);
        } else {
            System.out.println("更新失败:"+body);
        }
        return body;
    }
}
